@extends('layouts.admin')
@section('style')
@endsection
@section('content')
<div class="admin_main">
    <div class="admin_header_fixed">
        <div class="admin_header clearfix">
            <div class="title"><i></i>新增角色</div>
            <div class="action">
                <b></b>
                <div class="layui-btn-group layui-btn-group-only">
                    <a class="layui-btn layui-btn-primary layui-btn-small " href="{{ url('role') }}">
                        <i class="fa fa-reply"></i> 返回列表
                    </a>
                </div>
            </div>
        </div>
    </div>
    <div class="admin_base">
         <div class="box_form">
            <div class="box_content">
                <form method="post" action="{{ url('role') }}"  id="UserForm"  class="layui-form" novalidate="1">
                    {{ csrf_field() }}
                    <fieldset class="layui-elem-field">
                        <legend style="font-size:16px;margin-bottom:10px">角色基本信息</legend>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span>*</span>角色标识</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" required lay-verify="required"   placeholder="请输入角色标识" value="" id="name"  class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label"><span>*</span>角色名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="display_name"  lay-filter="required"  value="" id="display_name" placeholder="请输入角色名称" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text">
                            <label class="layui-form-label"><span>*</span>角色描述</label>
                            <div class="layui-input-inline">
                                <textarea name="description" placeholder="请输入角色描述" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </fieldset>
                    <div class="layui-form-item admin_bottom">
                        <div class="layui-input-inline">
                            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="admin_bottom"></div>
</div>
@endsection
@section('script')
    <script type="text/javascript">
        layui.use(['form','element','layer','utils'], function(){
            var form = layui.form;
            var element= layui.element;
            var URL = layui.utils.URL;
            var errorTip = layui.utils.errorTip;
            var $ = layui.$;
            form.on('submit(save)',function(data){
                var url  = $(data.form).prop('action');
                var data = data.field;
                URL.post(url,data,{
                    dataType:'json',
                    success:function(res){
                        if(res.code==1){
                            layer.msg(res.message,{icon:6,times:2000},function(){
                                document.location.href = '/role';
                            })
                        }else{
                            var errors = res.errors;
                            if(typeof errors!='undefined'){
                                errorTip(errors);
                            }else{
                                layer.msg(res.message,{icon:5,times:2000});
                            }
                        }
                    }
                })
                return false;
            })
        });
    </script>
@endsection